package com.ham.mud.commands;

import com.ham.mud.ServerConnection;
import com.ham.mud.TargetableService;
import com.ham.mud.characters.player.Player;
import com.ham.mud.characters.player.PlayerService;
import com.ham.mud.items.Item;

import java.util.ArrayList;

/**
 * Created by hlucas on Jun 21, 2011 at 3:54:10 PM
 */
public class UnequipCommand extends PlayerCommand {
    @Override
    public void execute(ServerConnection connection, String[] params) {              
        if(params.length == 0) {
            connection.printSolo("Unequip what?");
            return;
        }
        
        Player player = connection.getPlayer();
        String searchFor = params[0];
        Item item = (Item) TargetableService.findTarget(searchFor, new ArrayList<Item>(player.getEquipment().values()));
        if(item == null) {
            connection.printSolo("You don't have that item.");
            return;
        }

        player.unequip(item, connection);
        PlayerService.save(player);
    }

    @Override
    protected String getCommandName() {
        return "remove";
    }
}
